so I'm trying to make a node package for the Roblox API, and inside of it, I have decided taking a OOP approach.
The issue comes in when attributes such as <RobloxUser>.id are showing up as undefined unexpectedly, I added console.log statements and the API calls are returning the expected values.
Originally I added an async IIFE inside the class constructor to make calls using async/await syntax and I was having this issue. So I figured it was a scoping issue or something of the sort and changed my syntax to "callback hell" styled syntax and am still having this issue.
To test my theory I set a variable <RobloxUser>.test = 0 then used console.log, it printed 0 as expected, then I set it equal to 2 inside the callback and printed it outside the callback and it printed 0 again.
In all my time working with Javascript I have never once had an issue similar to this, if anyone may offer me some insight as to how I can solve this problem I would greatly appreciate it.
RobloxUser class code:
class RobloxUser {
constructor(response) {
axios.get(`https://users.roblox.com/v1/users/${response.data.Id}`).then(res => {
this.username = res.data.name;
this.displayName = res.data.displayName;
this.id = res.data.id;
this.info = { };
let joinDate = new Date(res.data.created);
let now = new Date();
this.info.accountAge = Math.round(Math.abs((joinDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)));
this.info.isBanned = res.data.isBanned;
});
axios.get(`https://friends.roblox.com/v1/users/${this.id}/friends/count`).then(res => {
this.info.friendCount = res.data.count;
});
axios.get(`https://friends.roblox.com/v1/users/${this.id}/followings/count`).then(res => {
this.info.followingCount = res.data.count;
});
axios.get(`https://friends.roblox.com/v1/users/${this.id}/followers/count`).then(res => {
this.info.followerCount = res.data.count;
});
axios.get(`https://users.roblox.com/v1/users/${this.id}/username-history`).then(res => {
this.info.pastUsernames = res.data.data.map(data => data.name)
});
}
getThumbnailURL() {
}
}